package com.lianniu.web.login;


import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import com.lianniu.web.baseService.user.service.impl.FrontUserServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lianniu.web.base.BaseResult;
import com.lianniu.web.baseService.user.service.IFrontUserService;
import com.lianniu.web.baseService.user.service.IUserLoginLogService;



/**
 * 
 * @ClassName: LoginFilterController
 * @Description: TODO

 * @date: 2016年3月16日 下午7:23:24
 */
@Controller
@RequestMapping("/rest")
public class LoginController {
  private final static Logger logger = Logger.getLogger(LoginController.class);
  @Resource
  private IFrontUserService frontUserService;
  
  @Resource
  private IUserLoginLogService userLoginLogService;
  /**
   * @Title: userCheckFail 
   * @Description: 用户登陆
   * @author: lzz
   * @param request
   * @param username
   * @param userpasswd
   * @param codeUuid
   * @param code
   * @param times
   * @return
   * @date: 2016年8月4日 下午5:56:08 
   * @return: BaseResult 
   */
  @RequestMapping(value = {"/login"}, method = RequestMethod.POST)
  public @ResponseBody BaseResult userCheckFail(HttpServletRequest request, String username,
      String userpasswd, String codeUuid, String code,int times,String isSupply) {
    logger.info("LoginController userCheckFail begin.");
    boolean supply = false;
    if(StringUtils.isBlank(isSupply))
    {
      isSupply = FrontUserServiceImpl.TYPE_BUYER;
    }
    BaseResult baseResult = frontUserService.login(request, username, userpasswd, codeUuid, code, times,isSupply);
    logger.info("LoginController userCheckFail end.");
    return baseResult;
  }
  @RequestMapping(value = {"/getMemuList"}, method = RequestMethod.GET)
  public @ResponseBody BaseResult getMemuList(HttpServletRequest request, String staffid,
      String sysinfo_id) {


    return BaseResult.success();
  }
  
  /**
   * 查看用户是否登录
   * @param request
   * @param username
   * @param userpasswd
   * @return
   */
  @RequestMapping(value = {"/isLogin"}, method = RequestMethod.POST)
  public @ResponseBody BaseResult isLogin(HttpServletRequest request, String username,
      String userpasswd) {
    logger.info("LoginController isLogin begin.");
    logger.info("登陆的人 为 ------------------------"+ username);
    BaseResult baseResult = frontUserService.isLogin(request, username, userpasswd);
    logger.info("LoginController isLogin end.");
    return baseResult;
  }
  
}
